package com.rentcars.controller;

import com.github.pagehelper.Page;
import com.rentcars.entity.CarYearcheck;
import com.rentcars.service.CarYearcheckService;
import com.rentcars.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 赵瑞硕
 * 车辆管理年检
 */
@RestController
@RequestMapping("/checks")
public class CarYearcheckController {
    @Autowired
    private CarYearcheckService carYearcheckService;
    @RequestMapping(value="/getPages")
    public Map queryCarInsurByPage(int pageNum, int pageSize, String carid){
        Map map=new HashMap();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("carid",carid);
        Page page= carYearcheckService.queryCarInsurByPage(map);
        map.put("page",page);
        map.put("totalPage",page.getPages());
        return  map;
    }
    @RequestMapping(value="/select")
    public ModelAndView toIn(){
        return new ModelAndView("yearcheck-list");
    }
    @RequestMapping(value="/del")
    public int delIn(String recordid){
        return   carYearcheckService.deleteByPrimaryKey(recordid);
    }
    @RequestMapping(value="/add")
    public ModelAndView aDDsin(){
        return new ModelAndView("yearcheck-add");
    }
    @RequestMapping(value="/edit")
    public ModelAndView getIn(String recordid) throws  ParseException {
        CarYearcheck carYearcheck=carYearcheckService.selectByPrimaryKey(recordid);
        Map<String,Object>rsmap=new HashMap<>();
        Date addtime= DateUtils.getDate(carYearcheck.getAddtime());
        Date usecartime= DateUtils.getDate(carYearcheck.getUsecartime());
        Date returntime= DateUtils.getDate(carYearcheck.getReturntime());
        Date nexttime= DateUtils.getDate(carYearcheck.getNexttime());
        rsmap.put("addtime",addtime);
        rsmap.put("usecartime",usecartime);
        rsmap.put("returntime",returntime);
        rsmap.put("nexttime",nexttime);
        rsmap.put("datas",carYearcheck);
        return new ModelAndView("yearcheck-edit",rsmap);
    }
    @RequestMapping(value="/updata")
    public int upIn(CarYearcheck carYearcheck) {
        return carYearcheckService.updateByPrimaryKeySelective(carYearcheck);
    }
    @RequestMapping(value="/addsss")
    public int addIn(CarYearcheck carYearcheck){
        CarYearcheck car=carYearcheckService.selectByPrimaryKey(carYearcheck.getRecordid());
        if (car==null){
            return carYearcheckService.insertSelective(carYearcheck);
        }else {
            return 0;
        }

    }
}
